package com.oocl.euc.daoTest;

import static org.junit.Assert.*;

import java.util.List;

import org.bson.types.ObjectId;
import org.junit.Assert;
import org.junit.BeforeClass;
import org.junit.Test;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import com.alibaba.fastjson.JSON;
import com.oocl.euc.dao.DishDao;
import com.oocl.euc.dao.impl.DishDaoImpl;
import com.oocl.euc.entity.Dish;
import com.oocl.euc.service.DishService;

public class DishDaoTest {
	private static ApplicationContext ac;
	private static DishDao ddi;
	@BeforeClass
	public static void init(){
		ac = new ClassPathXmlApplicationContext("applicationContext.xml");
		ddi=(DishDao)ac.getBean("dishDao");
	}
	@Test
	public void testAddDish() {
		Dish d=new Dish();
		d.setDname("mmm");
		d.setPrice(2.22);
		ddi.addDish(d, "57ff434db8828c23c0aa14a1");
		
	}

	@Test
	public void testDeleteDish() {
		Assert.assertTrue(ddi.deleteDish("57ff2e95b8828c23e4c9557c")==1);
	}

	@Test
	public void testFindDishesByMid() {
		List<Dish> dishes=ddi.findDishesByMid("57ff29d7b8828c23c412e6f8");
		for(Dish d:dishes){
			System.out.println(JSON.toJSONString(d.getMerchant()));
		}
		Assert.assertNotNull(dishes);
	}

	@Test
	public void testFindDishByDid() {
		Dish dish=ddi.findDishByDid("57ff3e3cb8828c1974a9debb");
		System.out.println(JSON.toJSONString(dish));
		Assert.assertNotNull(dish);
	}

	@Test
	public void testUpdateDish() {
		Dish d=ddi.findDishByDid("57ff3e3cb8828c1974a9debb");
		d.setDname(d.getDname()+"222");
		Assert.assertTrue(ddi.updateDish(d)==1);
		
	}

}
